#include<map>
#include<vector>
using namespace std;
class MyCalendarTwo {
private:
    map<int, int> helper_map;
public:
    MyCalendarTwo() {

    }

    bool book(int start, int end) {
        ++helper_map[start];
        --helper_map[end];
        int count = 0;
        for (auto it = helper_map.begin(); it != helper_map.end(); ++it) {
            count += it->second;
            if (count == 3) {
                --helper_map[start];
                ++helper_map[end];
                if (helper_map[start] == 0)
                    helper_map.erase(start);
                if (helper_map[start] == 0)
                    helper_map.erase(end);
                return false;
            }
        }
        return true;
    }
};

/**
 * Your MyCalendarTwo object will be instantiated and called as such:
 * MyCalendarTwo* obj = new MyCalendarTwo();
 * bool param_1 = obj->book(start,end);
 */